#include<bits/stdc++.h>
using namespace std;
//双指针
class Solution {
public:
    vector<int> sortedSquares(vector<int>& nums) {
        vector<int> ans(nums.size());
        int left=0; int right=nums.size()-1;
        int n = nums.size()-1;
        while(left<=right){
            if(abs(nums[left])<abs(nums[right])){
                ans[n--]=nums[right]*nums[right];
                --right;
            } 
            else {
                ans[n--]=nums[left]*nums[left];
                ++left;
            }
        }
        return ans;
    }
};

//归并
